<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="uct" uri="/WEB-INF/uct.tld" %>
<%@ taglib prefix="portal" uri="/WEB-INF/portal.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<%@ include file="/common/sale/include/common-base.jsp"%>
  <script src="${ctx}/js/jquery-tools.min.js"></script>
  <script type="text/javascript" src="${ctx}/js/utr/util.js"></script>
  <script type="text/javascript" src="${ctx}/js/funds.js"></script>
  <title>资金余额</title>
  <!-- Tell the browser to be responsive to screen width -->
</head>
<body class="hold-transition ${sysUserColor} sidebar-mini">
<div class="wrapper">
 <!-- top start -->
  <%@include file="/common/sale/top-user.jsp" %>
  <!-- top end -->
<!-- left start -->
  <%@include file="/common/sale/left-user.jsp" %>
<!-- left end-->
 <!-- main start -->
  <div class="content-wrapper">
	  <div class="content">
	    <div class="row">
	       <div class="col-lg-12 rightmt">
	          <!-- right_box start -->
	           <div class="right_box">
	               <h4 class="user_title"><p><i class="fa fa-yen"></i><span>资金金额</span></p></h4>
                   <div class="ov">
                   <div id="myPurse" style="display: block;">
	                 	<div class="col-md-3 col-sm-6 col-xs-12">
					          <!-- small box -->
					          <div class="small-box bg-yellow">
					            <div class="inner">
					              <p>名称：${loginUser.userCname}</p>
					              <p>账号：${loginUser.user.cardNum}</p>
					            </div>
					            <div class="icon">
					            </div>
					          </div>
						 </div>
	                    		
                   		<div class="col-md-3 col-sm-6 col-xs-12">
				          <div class="info-box money_border">
				            <span class="info-box-icon bg-aqua"><i class="fa fa-rmb"></i></span>
				            <div class="info-box-content">
				              <span class="info-box-text">总金额（元）</span>
				              <span class="info-box-number" style="font-size: 15px;" id="fundsAmtTotal"></span>
				            </div>
				            <!-- /.info-box-content -->
				          </div>
				          <!-- /.info-box -->
				         </div>
						         
                   		<div class="col-md-3 col-sm-6 col-xs-12">
				          <div class="info-box money_border">
				            <span class="info-box-icon bg-green"><i class="fa fa-rmb"></i></span>
				            <div class="info-box-content">
				              <span class="info-box-text">有效金额（元）</span>
				              <span class="info-box-number" style="font-size: 15px;" id="fundsM1"></span>
				            </div>
				            <!-- /.info-box-content -->
				          </div>
				          <!-- /.info-box -->
				        </div>
	                    		
                   		<div class="col-md-3 col-sm-6 col-xs-12">
				          <div class="info-box money_border">
				            <span class="info-box-icon bg-yellow"><i class="fa fa-rmb"></i></span>
				            <div class="info-box-content">
				              <span class="info-box-text">冻结金额（元）</span>
				              <span class="info-box-number" style="font-size: 15px;" id="fundsM2"></span>
				            </div>
				            <!-- /.info-box-content -->
				          </div>
				          <!-- /.info-box -->
				        </div>
	                 </div>
	              
	                 <!-- 充值  start-->
	               <div class="col-xs-12">
	                 <div class="chongzhi" style="display:none;"><!-- 需要隐藏 -->
				        	<form id="myForm2" name="myForm2" >
				        		<input type="hidden" id="directionType" value="${param.direction }" />
					       		<input type="hidden" name="customerNo" value="${fundsUser.userName}"/><br/>
					       		<!-- <input type="radio" name="direction" <c:if test="${param.direction=='in' }">checked</c:if> value="in"/>线下充值 &nbsp; &nbsp;
					       		 --><input type="radio" name="direction" <c:if test="${param.direction=='out' }">checked</c:if> value="out"/>实时提现 
					       		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					       		操作金额：<span><input type="text" class="form-control" style="width: 30%;" id="amount" name="amount" size="10" maxlength="9"/>元  </span> &nbsp;&nbsp; 
				       		     <input type="button" value=" 提 交 " class="btn btn-danger" style="width: 100px;" onclick="checkSubmitInfo()"/>
				       		    <!-- <input type="button" value=" 转账充值 " class="orgbtn_s" onClick="subFunds4()"/>&nbsp;&nbsp; 
				       		    <input type="button" value=" 在线充值 " class="orgbtn_s" onClick="subFunds2()"/>&nbsp;&nbsp; 
				       		    <input type="button" value=" 提现 " class="bluebtn_s" onClick="subFunds3()"/>
				       		     -->
				       		     <div class="form-group f12 fx8">
								 <i class="fa fa-info-circle"></i>温馨提示：资金充值请联系交易所管理员
								 </div>
				       		</form>
				       	</div>
				   </div>
	          <!-- 充值  end-->
	           </div>
               </div>
              <!-- right_box end -->
              
              <!-- right_box2 end -->
              
              
              
            </div>
            <!-- right end -->
     </div>
  <!-- mainrow end -->
</div>
<!-- main end -->

	       
     
     
     </div>   
  </div>
  
 <!-- main end-->
  
  <!-- foot start -->
  <%@include file="/common/sale/foot-user.jsp" %>
  <!-- foot start -->
  
</div>
  
</div>
</body>

</html>
<script>
var clickMenu = 'my-funds';
var page_web = "${page_web}";
var userName,fundAcc,cardNo;
function opDone(flag,msg){
	
}

	$(function(){
		indexCheckMyFundsV3();
	});
	
	function indexCheckMyFundsV3(){
		var index_load = layer.load(1, {shade: false});
		$.ajax({
			type:'get',dataType:'json',
			//url: common_list_url+'?doCode=F001',
			url: common_list_url+'?doCode=F003',
			async: true,data: {f:new Date().getTime()},
			success:function(result)	{
				console.log(result);
				layer.close(index_load);
				var flag = result.flag;
				var msg = result.msg;
				msg = JSON.parse(msg);
				if("T"==flag){
					userName = msg.createUserName;
					fundAcc = msg.userName;
					cardNo = msg.bankAccount;
					//alert(fundAcc+":"+userName+":"+cardNo);
					getMyFudsBalance();
				}else if("F1"==flag){
					layer.alert("资金账户不存在，请先去开通",function(i){
						window.location.href=page_web+"/user/index";
					});
				}
			}
		});
	}
	//查询我的资金余额
	function getMyFudsBalance(){
		var index_load = layer.load(1, {shade: false});
		$.ajax({
			type:'get',
			url: common_list_url+'?doCode=F004',
			async: false,
			data: {f:new Date().getTime()},
			dataType:'json',
			success:function(result)	{
				var flag = result.flag;
				//alert(flag);
				layer.close(index_load);
			  	console.log(result);
			  	if("T"==flag){
			  		var obj = result.msg;
			  		$("#fundsAmtTotal").text(fmoney(obj.amtTotal*1/100));
			  		$("#fundsM1").text(fmoney(obj.m1*1/100));
			  		$("#fundsM2").text(fmoney(obj.m2*1/100));
			  	}
			}
		});
	}
	function checkSubmitInfo(){
		var amount = $("#amount").val().trim();
		if(amount<=0){
			layer.tips('请输入大于零的金额！', '#amount', {tips: 1});
			$("#amount").val("");
			return;
		}
		var direction = $("input[name='direction']:checked").val();
		var m1 = $("#fundsM1").text().trim();
		if("out"==direction&&amount*1>m1){
			layer.tips('您输入的金额大于有效金额，请重新输入！', '#amount', {tips: 1});
			$("#amount").val("");
			return;
		}
		//submitFunds();
		if("in"==direction){//充值打开充值银行测试页面
			window.open("${page_web}/bank/recharge/recharge?secuNo=3165&DraweeAccNo="+cardNo+"&DraweeAccName="+userName+"&PayeeAccNo="+fundAcc+"&PayeeAccName="+userName+"&Amt="+amount);
			return;
		}
		//暂时修改为访问银行接口-提现
		bankTx(amount);
	}
	function bankTx(amt){
		var paramData = {"amt":amt,"userId":"${loginUser.userId}","userEname":"${loginUser.userEname}","doCode":"BANK_CNP_T000008"};
		$.ajax({
			type:'post',
			url:"${ctx}/bank/",
			async:false,
			dataType:"json",
			data:paramData,
			success: function(myData){
				//根据返回结果执行
				if(myData.flag=="T"){
					//格式化json
					var jsonMsg = JSON.parse(myData.msg);
					jsonMsg = JSON.stringify(jsonMsg.transOutput);
					jsonMsg = JSON.parse(jsonMsg);
					layer.tips('成功：'+jsonMsg.message, '#amount', {tips: 1});
				}else if(myData.flag=="F"){
					var msg = myData.msg;
					layer.tips(msg, '#amount', {tips: 1});
				}
			}
		});	
	}
</script>
